/*
 *
 * Saturn Framework Co.Limt
 * Copyright (c) 2012-2019 tanks, Inc. All rights reserved.
 */
 
package com.saturn.config.server.base.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.saturn.config.server.base.dto.ConfigInfo;
import com.saturn.config.server.base.dto.ConfigLogDto;
import com.saturn.config.server.base.entity.ConfigLog;

/**
 * <dl>
 *    <dt><b>Title:</b></dt>
 *    <dd>
 *    	none
 *    </dd>
 *    <dt><b>Description:</b></dt>
 *    <dd>
 *    	<p>配置操作日志表
 *    </dd>
 *
 * @author tanks
 * @date 2019-07-08 15:58:43
 */
public interface ConfigLogMapper extends BaseMapper<ConfigLog> {

	/**
	 * 查询分页
	 * @param page
	 * @param queryWrapper
	 * @return
	 */
	IPage<ConfigLogDto> queryPage(IPage<ConfigLogDto> page,@Param("map") Map<String,Object> params);
	
	/**
	 * 通过批量删除配置文件的数据
	 * @param configIds
	 * @return
	 */
	public int deleteBatchByConfigIds(@Param("configIds") List<String> configIds,@Param("isCast") String isCast);
	
	/**
	 * 查询未广播的配置信息
	 * @return
	 */	
	@Select("SELECT t3.env_type,t3.app_name,t2.* " + 
			"FROM config_log t1 " + 
			"INNER JOIN app_config t2 ON t1.config_id = t2.config_id " + 
			"INNER JOIN app_info t3 ON t1.app_id = t3.app_id " + 
			"WHERE t1.IS_CAST = '0'")
	public List<ConfigInfo> queryCastAppConfig();
	

	/**
	 * 查询变更的应用配置的应用名称
	 * @return
	 */
	@Select("select * from app_config t0 where t0.app_id in (SELECT t1.app_id from config_log t1 WHERE t1.IS_CAST = '0') and t0.config_key='spring.application.name'")
	public List<ConfigInfo> queryCastApplicationName();
	
	/**
	 * 更新广播状态
	 * @return
	 */
	@Select("update config_log set is_cast='1'")
	public void updateCast();
	
	
	/**
	 * 通过版本信息删除配置日志
	 * @param wrapper
	 * @return
	 */
	public Integer deleteByVersion(@Param("map") Map<String,Object> params);
}
